package SegmentTree._729_MyCalendarI;

import java.util.TreeMap;

public class MyCalendar {
    TreeMap<Integer,Integer> tree;
    public MyCalendar() {
        this.tree = new TreeMap<>();
    }

    public boolean book(int start, int end) {
        Integer prev = tree.floorKey(start);
        Integer next = tree.ceilingKey(start);
        if ((prev == null || tree.get(prev) <= start) &&
                (next == null || end <= next)) {
            tree.put(start, end);
            return true;
        }
        return false;
    }
}
